﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows;

namespace MVVMLab
{
    public class LabContactViewModel : ViewModelBase
    {
 
        #region " Properties "
        private LabContact _labContact;
        public LabContact LabContact
        {
            get { return _labContact; }
            set
            {
                if (_labContact != value)
                {
                    _labContact = value; 
                    OnPropertyChanged("LabContact");
                } 
            }
        }

        #endregion

        #region " Command Properties "

        
        private ICommand _newCommand;
        public ICommand NewCommand
        {
            get
            {
                if (_newCommand == null)
                {
                    _newCommand = new RelayCommand(NewExecute);
                }
                return _newCommand;
            }
        }

        private ICommand _saveCommand;
        public ICommand SaveCommand
        {
            get
            {
                if (_saveCommand == null)
                {
                    _saveCommand = new RelayCommand(SaveExecute, CanSaveExecute);
                }
                return _saveCommand;
            }
        }

        #endregion

        #region " Constructors "

        public LabContactViewModel()
        {

        }

        #endregion

        #region " Command Methods "

        private void NewExecute(object param)
        {
            //TODO: Technically you should save old one,etc  
            this.LabContact = new LabContact();

        }

        private void SaveExecute(object param)
        {
            //In a real applicaiton implement saving the LabContact to the database
            //In M-V-VM applications the ViewModel does not raise UI Message Boxes.
            //  Instead, a Logger Service is used.
            MessageBox.Show("Saved");
        }

        private bool CanSaveExecute(object param)
        {
            return base.UIValidationErrorCount == 0 && this.LabContact.Errors.Count == 0;
        }
        #endregion

    }



}
